package com.zekai.calculator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HistoryRepository {
    private static HistoryRepository instance;

    private List<String> expressions = new ArrayList<>();
    private List<String> results = new ArrayList<>();
    private HistoryRepository() {
        // 私有构造函数，防止外部实例化
    }

    public static synchronized HistoryRepository getInstance() {
        if (instance == null) {
            instance = new HistoryRepository();
        }
        return instance;
    }

    // 添加表达式和结果到仓库
    public void addExpressionAndResult(String expression, String result) {
        expressions.add(expression);
        results.add(result);
    }

    // 获取所有表达式，倒序
    public List<String> getAllExpressions() {
        List<String> reversedExpressions = new ArrayList<>(expressions);
        Collections.reverse(reversedExpressions);
        return reversedExpressions;
    }

    // 获取所有结果，倒序
    public List<String> getAllResults() {
        List<String> reversedResults = new ArrayList<>(results);
        Collections.reverse(reversedResults);
        return reversedResults;
    }
}
